package com.wuwei.tran;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ConsoleLogger {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleLogger.class);

    public static void redirectOutputToLog() {
        OutputStream outputStream = new OutputStream() {
            @Override
            public void write(int b) throws IOException {
                LOGGER.info(String.valueOf((char) b));
            }
        };

        // Redirect System.out
        System.setOut(new PrintStream(outputStream, true));

        // Redirect System.err
        System.setErr(new PrintStream(outputStream, true));
    }
}
